<template>
  <div class="detail" v-if="hotSongs">
    <div class="img">
      <img :src="artist.img1v1Url" />
      <div class="title">
        <h3 class="songList">
          <van-icon
            name="arrow-left"
            class="back"
            @click="$router.go(-1)"
          />歌手
        </h3>
        <div class="tag">
          {{ artist.name }}{{ artist.alias[0] ? "('+artist.alias[0]+')" : "" }}
        </div>
      </div>
    </div>
    <div :class="{ card: true, bottom: playerId }">
      <div class="head" @click="setIdFrist">
        <van-icon name="play-circle-o" />
        播放全部<span>(共{{ hotSongs.length }}首)</span>
      </div>
      <div
        class="song"
        v-for="(item, index) in hotSongs"
        :key="item.id"
        @click="setId(item.id)"
      >
        <div class="num">{{ index + 1 }}</div>
        <div class="right">
          <div class="up">{{ item.name }}</div>
          <div class="down">
            <span v-for="value in item.ar" :key="value.id"
              >{{ value.name }}&nbsp;</span
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getArtists } from "@/api/singer";
export default {
  props: ["playerId", "flag"],
  data() {
    return {
      id: this.$route.params.id,
      hotSongs: null,
      length: 0,
      artist: null,
    };
  },
  methods: {
    setId(id) {
      this.$emit("get-player-id", id);
      console.log("传递歌单id", this.$route.params.id);
      this.$emit("update:flag", true);
      this.$emit("get-play-all-id", this.$route.params.id); //传递歌单id
    },
    // 播放全部
    setIdFrist() {
      this.$emit("get-player-id", this.hotSongs[0].id);
      this.$emit("update:flag", true);
      this.$emit("get-play-all-id", this.$route.params.id); //传递歌单id
    },
    //   获取歌手的歌曲
    async getArtists() {
      const { artist, hotSongs } = await getArtists({
        id: this.id,
      });
      console.log(hotSongs);
      this.hotSongs = hotSongs;
      this.artist = artist;
    },
  },
  created() {
    this.getArtists();
  },
};
</script>

<style lang="less" scoped>
.detail {
  .img {
    position: relative;
    img {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 267px;
    }
    .title {
      position: absolute;
      top: 0;
      left: 0;
      padding: 12px;
      color: #fff;
      .songList {
        font-size: 16px;
        line-height: 16px;
        height: 17px;
        color: #fff;
        .back {
          font-size: 17px;
          margin-right: 6px;
        }
      }
      .tag {
        margin-top: 185px;
        font-weight: bold;
        color: #fff;
        font-size: 16px;
      }
    }
  }

  .bottom {
    padding-bottom: 53px;
  }
  .card {
    height: 61vh;
    overflow-x: hidden;
    margin: 0 1px;
    background-color: #f2f3f4;
    position: relative;
    top: 260px;
    font-size: 15px;
    line-height: 15px;
    border-radius: 7px;
    .head {
      padding: 9px 14px;
      border-bottom: 2px solid #e5e5e5;
      color: #484a4a;
      .van-icon {
        margin-right: 11px;
      }
      span {
        line-height: 16px;
        height: 16px;
        font-size: 15px;
        color: #b5b6b6;
      }
    }
    .song {
      padding: 12px 14px 9px;
      height: 55px;
      align-items: center;
      border-bottom: 2px solid #e5e5e5;
      display: flex;
      .num {
        font-size: 11px;
        width: 31px;
        padding-left: 4px;
        color: #484a4a;
      }
      .right {
        width: 80%;
        .up {
          width: 80%;
          font-size: 16px;
          margin-bottom: 7px;
          color: #484a4a;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          word-break: keep-all;
        }
        .down {
          width: 80%;
          font-size: 11px;
          color: #b2b2b2;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          word-break: keep-all;
        }
      }
    }
  }
}
</style>
